import React from 'react';

import { connect } from 'react-redux';

class Main extends React.Component {
    render() {
        return (
            <section>
                <hr />
                <h3>页面主体{this.props.num}</h3>
                <button onClick={this.props.aaaa}>改仓库状态</button>
                <hr />
            </section>
        );
    }
}

const mapStateToProps = (state) => ({
    num: state.num
});

const mapDispatchToProps = (dispatch) => ({
    aaaa() {
        // 定义 action 对象
        const action = {
            type: 'add',
            value: 1
        };
        // 调用 dispatch 传递 action，自动触发管理员函数 reducer 运行
        dispatch(action);
    }
});

// connect() 调用后返回一个用来构建超级组件的函数。
const SuperMain = connect(mapStateToProps, mapDispatchToProps)(Main);

export default SuperMain;